<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>Document</title>
<link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
<link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
<link rel="stylesheet" href="../assets/app/css/app.css" />
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<style>li img{width:60px;height:60px;}.group_listitem{background:#fff;}.group_listitem li{margin:5px auto 0px !important;}</style>
</head>
<body style="background:#f5f5f5;">
<!--通用顶部-->
<div id="ios-top-box">
    <div id="header" class="bar bar-nav">
    <div class="titlebar">
    <a href="javascript:appClose('userteambuylist',api);"><i class="iconfont iconline-arrow-left"></i></a>
    <h1 class="title">创团记录</h1>
    </div>
    </div>
</div>
<!--通用顶部结束-->
<header class="bar bar-nav box_shadow head_a" style="margin-top:43px;">
	<a href="javascript:;" class="selected_bottom all">全部商品</a>
	<a href="javascript:;" class="action">进行中</a>
	<a href="javascript:;" class="show">已揭晓</a>
</header>
<section style="margin-top:95px !important;">
<div class="scroller create_goods">
	<div class="team_record">
	</div>
	<div class="block10"></div>
	<ul class="search-ul load-more" style="display: none;">
	<li><button class="btn btn-block btn-more" id="loadmore" style="background:#fbfbfb;border-color:#ccc;">加载更加</button></li>
	</ul>
</div>
</section>
</body>
<script type="text/javascript">
function tdataserver(team_goods_id){
	if(!team_goods_id){
		api.alert({msg:'参数错误'});
		return;
	}
	localData.set('team_goods_id',team_goods_id);
	api.openWin({name:'js_result','url':'./js_result.html',reload:true});
}
function teambuydetail(team_goods_id){
	if(!team_goods_id){
		api.alert({msg:'参数错误'});
		return;
	}
	localData.set('team_goods_id',team_goods_id);
	api.openWin({name:'createbuydetail','url':'./createbuydetail.html',reload:true});
}
apiready = function(){
	$(function(){

		if(!getUserinfo()){
			$.PageDialog.fail('请登录用户');
			return;
		}
		$('.head_a a').click(function(){
			$('.head_a a').removeClass('selected_bottom');
			$(this).addClass('selected_bottom');
		});
		var page = 1;
		var flag = true;
		var type = 'all';
		var tag = 1;
		$('.all').click(function(){
			$('.team_record').html('');
			type = 'all';
			page = 1;
			flag = true;
			$('.load-more').hide();
			api.showProgress({title:'加载中',text:''});
			tag = 1;
			ajaxData(page,flag,type,tag);
		});
		$('.action').click(function(){
			$('.team_record').html('');
			type = 'action';
			page = 1;
			flag = true;
			$('.load-more').hide();
			api.showProgress({title:'加载中',text:''});
			tag = 2;
			ajaxData(page,flag,type,tag);
		});
		$('.show').click(function(){
			$('.team_record').html('');
			type = 'show';
			page = 1;
			flag = true;
			$('.load-more').hide();
			api.showProgress({title:'加载中',text:''});
			tag = 3;
			ajaxData(page,flag,type,tag);
		});
		function init(page,flag,type,tag){
			$('.load-more').hide();
			ajaxData(page,flag,type);
		}
		api.showProgress({title:'加载中',text:''});
		init(page,flag,type,tag);
		
		function ajaxData(page,flag,type,tag){
			if(flag ==  false){
				return;
			}
			var userinfo = getUserinfo();
			GetJPData(config.url+'/app.php?act=getteamrecord&uid='+userinfo.uid,{page:page,type:type},function(json){
				var txt = '';
				var html = '';
				for(var i=0; i < json.length; i++){
					if(json[i]['title'] == undefined){
						flag = false;
						$('.btn-more').text('已经到底了');
						if(json[i]['sum'] == 0){
							txt = '暂无数据';
							$('.team_record').html('<p style="text-align:center;padding:10px;">'+txt+'</p>').fadeIn('fast');
						}
						break;
					}
					html += '<ul class="listitem group_listitem">';
					if(tag == 3){
						html += '<a style="display:block;" href="javascript:tdataserver('+json[i]['id']+');">';
					}else{
						html += '<a style="display:block;" href="javascript:teambuydetail('+json[i]['id']+');">';
					}
					html += '<li><img data-original="'+config.upload_url+'/'+json[i]['thumb']+'" class="img lazy"/>';
					html += '<div class="text">';
					html += '<p>'+json[i]['title']+'</p>';
					if(tag == 2){
						html += '<p><span>价值：'+json[i]['money']+'</span><button class="common-btn view_detail" style="margin-top:27px;">查看详情</button></p>';
						html += '<p><span>邀请码：'+json[i]['q_create_pwd']+'</span></p>';
						html += '<div class="goods_info_bottom"><div class="goods_con">进度：<progress max="100" value="'+parseInt((json[i]['canyurenshu']/json[i]['zongrenshu'])*100)+'" class="css3"><div class="progress-bar"></div></progress></div></div>';
					}else if(tag == 3){
						html += '<p><span>价值：'+json[i]['money']+'</span><button class="common-btn view_detail" style="margin-top:5px;">查看详情</button></p>';
						html += '<p><span>幸运夺宝码：'+json[i]['q_user_code']+'</span></p>';
						html += '<p><span>揭晓时间：'+json[i]['q_end_time']+'</span></p>';
					}else{
						html += '<p><span>价值：'+json[i]['money']+'</span><button class="common-btn view_detail" style="margin-top:27px;">查看详情</button></p>';
						html += '<p><span>团名称：'+json[i]['q_group_name']+'</span></p>';
						html += '<p><span>邀请码：'+json[i]['q_create_pwd']+'</span></p>';
					}
					html += '</div></li></a></ul>';
				}
				$('.team_record').append(html);
				lyzimg();
				if(flag == false){
					if(txt == ''){
						$('.btn-more').text('已经到底了');
					}else{
						$('.btn-more').text(txt);
						$('.container').width($(window).width());
					}
				}else{
					$('.container').width('auto');
					$('.btn-more').text('加载更多');
					}
				setTimeout(function(){
					api.hideProgress();
					if(type != 'action'){
						$('.load-more').show();
					}
					
				},2000);
			});
		}

		//加载更多
	 	$('#loadmore').click(function(){
	 	 	if(flag == false){
				return false;
	 	 	 }
			page += 1;
			flag = true;
			if($(this).text() == '已经到底了') return;
			api.showProgress({title:'加载中',text:''});
			$('.load-more').hide();
			ajaxData(page,flag,type);
		});
	});
};
</script>
</html>